package ThreadDemo;

public class JoinThread extends Thread {
    public JoinThread(String name) {
        super(name);
    }
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(getName() + " " + i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        new JoinThread("新县城").start();
        for (int i = 0; i < 100; i++) {
            if (i == 20) {
                JoinThread joinThread = new JoinThread("被join的线程");
                joinThread.start();
                joinThread.join(100);
            }
            System.out.println(Thread.currentThread().getName() + " " + i);
        }
    }
}
